﻿using BillHelper;
using DemoForBillOcr;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using TaxAssistantBase;

namespace ShiBieProject
{


    public partial class test : Form
    {
        [DllImport("opencv_zbar_qr.dll", EntryPoint = "GetQrCodeInfo")]
        public static extern int GetQrCodeInfo(ref byte input);
        [DllImport("opencv_zbar_qr.dll", EntryPoint = "GetQrCodeInfoInAndOut")]
        public static extern int GetQrCodeInfoInAndOut(ref byte input, ref byte output);
        [DllImport("opencv_zbar_qr.dll", EntryPoint = "qrcodeFind")]
        public static extern int qrcodeFind(ref byte input, ref byte output);
        public test()
        {
            InitializeComponent();
        }
        public static string ToRMB(object value)
        {
            try
            {
                string hash = double.Parse(value.ToString()).ToString("#L#E#D#C#K#E#D#C#J#E#D#C#I#E#D#C#H#E#D#C#G#E#D#C#F#E#D#C#.0B0A");
                string results = Regex.Replace(hash, @"((?<=-|^)[^1-9]*)|((?'z'0)[0A-E]*((?=[1-9])|(?'-z'(?=[F-L.]|$))))|((?'b'[F-L])(?'z'0)[0A-L]*((?=[1-9])|(?'-z'(?=[.]|$))))", "${b}${z}");
                hash = Regex.Replace(results, ".", delegate (Match m) { return "负圆空零壹贰叁肆伍陆柒捌玖空空空空空空空分角拾佰仟万億兆京垓秭穰"[m.Value[0] - '-'].ToString(); });
                if (hash.Substring(hash.Length - 1, 1) == "圆") { hash += "整"; }
                if (hash.Contains("整"))
                {
                    hash = hash.Replace("圆", "元");
                }
                return hash;
            }
            catch (Exception)
            {
                return "零";
            }
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            string tpresult = "";
            string apiurl = "/api/invoice/platform/getinvoicedata";
            InvoiiceOcrModel bpm = new InvoiiceOcrModel();
            InvoiiceOcrModel bpmlist23 = new InvoiiceOcrModel();
            bpm.invoiceNum = "01774520";
            string result = RestDataTool.PostInvoiceInfo(out tpresult, bpm, apiurl, out bpmlist23);
            List<InvoiiceOcrModel> bpmlist = getPiaoJuAllClick();


            //string texImgurl = AppDomain.CurrentDomain.BaseDirectory + "delerimg.txt";
            //string ImgUrl = @"D:\code\image_qrcode_ocrpost\image_qrcode_ocrpost\phoneInvoiceImg";
            //DirectoryInfo fileAll = new DirectoryInfo(ImgUrl);
            //foreach (string str in File.ReadAllLines(texImgurl, Encoding.UTF8))
            //{
            //    string[] complist = str.Split(':');
            //    if (complist.Count() > 1)
            //    {
            //        string imgName = complist[1];
            //        foreach (var file in fileAll.GetFiles()) {
            //            string deleteImgName = file.Name;
            //            if (imgName == deleteImgName) {
            //                string ingurl = ImgUrl + "\\"+ deleteImgName;
            //                if (File.Exists(ingurl))
            //                {
            //                    new FileInfo(ingurl).Attributes = FileAttributes.Normal;
            //                    File.Delete(ingurl);
            //                }
            //            }
            //        }
            //    }
            //}








            for (int i = 0; i < bpmlist.Count(); i++) {
                string invoiceNum = bpmlist[i].invoiceOcrSonListSet[0].invoiceNum;
                string gfcompanynames = bpmlist[i].invoiceOcrSonListSet[0].gfcompanyname;
                string xfcompanynames = bpmlist[i].invoiceOcrSonListSet[0].xfcompanyname;
                if (invoiceNum=="44654204"|| gfcompanynames=="上海禄幻互联网科技有限公司" || xfcompanynames == "上海禄幻互联网科技有限公司") {
                    string comp = bpmlist[i].companyName;
                    Console.Write(comp);
                }

            }
            List<BatchInfo> compList = HongFengCompanyOrVendorsTool.companyAll;
            List<BatchInfo> Vbilist = new List<BatchInfo>();
            string texurl = AppDomain.CurrentDomain.BaseDirectory + "VendorscompListData.txt";
            foreach (string str in File.ReadAllLines(texurl, Encoding.Default))
            {
                string[] complist = str.Split('-');
                if (complist.Count() > 1)
                {
                    BatchInfo bif = new BatchInfo();
                    if (!string.IsNullOrEmpty(complist[0]) && !string.IsNullOrEmpty(complist[1]))
                    {
                    }
                    bif.companyName = complist[0];
                    bif.companyTaxnum = complist[1];
                    Vbilist.Add(bif);
                }
            }
            int gfcomNum = 0;
            int gftaxNum = 0;
            int xfcomNum = 0;
            int xftaxNum = 0;
            string xfcompanyname = "";

            string xftaxnumber = "";

            string gfcompanyname = "";

            string gftaxnumber = "";
            string gftax = "";
            string xftax = "";
            //var WaitTestImg = AppDomain.CurrentDomain.BaseDirectory + "qrCodeFaileImg";
            //var qrCodeImg = AppDomain.CurrentDomain.BaseDirectory + "qrCodeImg";// GetFileNameWithoutExtension
            var WaitTestImg = AppDomain.CurrentDomain.BaseDirectory + "HandleWenJ\\20191216\\20191216";
            var qrCodeImg = AppDomain.CurrentDomain.BaseDirectory + "qrCodeImg";
            DirectoryInfo WaitTestImgInfo = new DirectoryInfo(WaitTestImg);
            List<string> name = new List<string>();
            string UrlZonghe = @"D:\code\image_qrcode_ocrpost\image_qrcode_ocrpost\qrCodeOcrFail";
            DirectoryInfo WaitTestImgInfos = new DirectoryInfo(UrlZonghe);
            //  foreach (var dirSon in WaitTestImgInfo.GetDirectories()) {
            foreach (InvoiiceOcrModel file in bpmlist)
            {
                //if (file.invoiceOcrSonListSet[0].invoiceNum=="11767315") {
                //    var a = "ss";
                //}
                //xfcompanyname = file.invoiceOcrSonListSet[0].xfcompanyname;

                //xftaxnumber = file.invoiceOcrSonListSet[0].xftaxnumber;

                //gfcompanyname = file.invoiceOcrSonListSet[0].gfcompanyname;

                //gftaxnumber = file.invoiceOcrSonListSet[0].gftaxnumber;
                //if (xftaxnumber==null) {
                //    xftaxnumber = "";
                //}
                //if (gftaxnumber==null) {
                //    gftaxnumber = "";
                //}
                //if (gftaxnumber.Length > 6)
                //{
                //    gftax = gftaxnumber.Substring(gftaxnumber.Length - 6, 6);
                //}
                //if (xftaxnumber.Length > 6)
                //{
                //    xftax = xftaxnumber.Substring(xftaxnumber.Length - 6, 6);
                //}

                //int inputsdegf = 0;
                //int inputsdexf = 0;
                //foreach (BatchInfo bf in Vbilist)
                //{
                //    string companyName = bf.companyName;
                //    string companyTaxnum = bf.companyTaxnum;
                //    string cotax = "";
                //    int a = 0;
                //    int b = 0;
                //    if (companyTaxnum.Length>6) {
                //        cotax = companyTaxnum.Substring(companyTaxnum.Length - 6, 6);
                //    }
                //    if (companyTaxnum == gftaxnumber)
                //    {
                //        gftaxNum++;
                //        gfcomNum++;
                //        inputsdegf++;
                //        a++;
                //        continue;
                //    }
                //    else
                //    {
                //        if (companyName == gfcompanyname)
                //        {
                //            gftaxNum++;
                //            gfcomNum++;
                //            inputsdegf++;
                //            a++;
                //            continue;
                //        }
                //        else
                //        {
                //            if (cotax == gftax)
                //            {
                //                gftaxNum++;
                //                gfcomNum++;
                //                inputsdegf++;
                //                a++;
                //                continue;
                //            }
                //        }
                //    }

                //    if (companyTaxnum == xftaxnumber)
                //    {
                //        xftaxNum++;
                //        xfcomNum++;
                //        inputsdexf++;
                //        b++;
                //        continue;
                //    }
                //    else
                //    {
                //        if (companyName == xfcompanyname)
                //        {
                //            xftaxNum++;
                //            xfcomNum++;
                //            inputsdexf++;
                //            b++;
                //            continue;
                //        }
                //        else {
                //            if (cotax == xftax)
                //            {
                //                xftaxNum++;
                //                xfcomNum++;
                //                inputsdexf++;
                //                b++;
                //                continue;
                //            }
                //        }
                //    }
                //    if (a==1&&b==1) {
                //        break;
                //    }
                //    if (a==2) {
                //        a = 1;
                //        gftaxNum--;
                //        gfcomNum--;
                //    }
                //    if (b==2) {
                //        b= 1;
                //        xftaxNum--;
                //        xfcomNum--;
                //    }
                //}
                //int temp = 0;
                //int temp1 = 0;
                //int temp2 = 0;
                //if (inputsdegf == 0)
                //{
                //    foreach (BatchInfo com in compList)
                //    {
                //        string company = com.companyName;
                //        string comtaxnu = com.companyTaxnum;
                //        string comtax = "";
                //        if (comtaxnu.Length > 6)
                //        {
                //            comtax = comtaxnu.Substring(comtaxnu.Length - 6, 6);
                //        }
                //        if (comtaxnu == gftaxnumber)
                //        {
                //            temp++;
                //            gftaxNum++;
                //            gfcomNum++;
                //            temp2++;

                //        }
                //        else
                //        {
                //            if (company == gfcompanyname)
                //            {
                //                temp++;
                //                gftaxNum++;
                //                gfcomNum++;
                //                temp2++;

                //            }
                //            else {
                //                if (comtax==gftax) {
                //                    temp++;
                //                    gftaxNum++;
                //                    gfcomNum++;
                //                    temp2++;

                //                }
                //            }
                //        }
                //    }
                //}
                //else
                //{
                //    temp++;
                //    inputsdegf = 0;
                //}
                //if (inputsdexf == 0)
                //{
                //    foreach (BatchInfo com in compList)
                //    {
                //        string company = com.companyName;
                //        string comtaxnu = com.companyTaxnum;
                //        string comtax = "";
                //        if (comtaxnu.Length>6) {
                //             comtax = comtaxnu.Substring(comtaxnu.Length - 6, 6);
                //        }    
                //        if (comtaxnu == xftaxnumber)
                //        {
                //            temp1++;
                //            xftaxNum++;
                //            xfcomNum++;


                //        }
                //        else
                //        {
                //            if (company == xfcompanyname)
                //            {
                //                temp1++;
                //                xfcomNum++;
                //                xftaxNum++;

                //            }
                //            else
                //            {
                //                if (comtax == xftax)
                //                {
                //                    temp1++;
                //                    xfcomNum++;
                //                    xftaxNum++;

                //                }
                //            }
                //        }
                //    }
                //}
                //else
                //{
                //    temp1++;
                //    inputsdexf = 0;
                //}
                //if (temp == 0)
                //{
                //    string img = file.imgUrl;
                //    WsdLogger.yxlog("error", "是被不成功图片" + img);
                //}
                //if (temp1 == 0)
                //{
                //    string img = file.imgUrl;
                //    WsdLogger.yxlog("error", "是被不成功图片" + img);
                //}
                string[] imgUrlName = file.imgUrl.Split('/');
                string imgName = imgUrlName[imgUrlName.Length - 1];
                string UrlZonghea = @"D:\code\image_qrcode_ocrpost\image_qrcode_ocrpost\phoneInvoiceImg";
                DirectoryInfo WaitTestImgInfoss = new DirectoryInfo(UrlZonghea);
                int ses = 0;
                foreach (var filese in WaitTestImgInfoss.GetFiles()) {
                    if (imgName== filese.Name) {
                        ses++;
                        break;
                    }
                }
                if (ses==0) {
                    string qcode = file.invoiceOcrSonListSet[0].qrCode;
                    if (string.IsNullOrEmpty(qcode))
                    {
                        //1、得到票据名称和票据批次号    
                        string batchime = file.batchtime;
                        foreach (var dir in WaitTestImgInfos.GetFiles())
                        {
                            if (dir.Name == imgName)
                            {
                                dir.CopyTo(@"D:\code\image_qrcode_ocrpost\image_qrcode_ocrpost\phoneInvoiceImg\" + imgName);
                                break;
                            }
                        }
                    }
                }
            }

            foreach (string infoName in name)
            {
                string urls = WaitTestImg + "\\" + infoName + ".jpg";
                if (File.Exists(urls))
                {
                    new FileInfo(urls).Attributes = FileAttributes.Normal;
                    File.Delete(urls);
                }
            }
            //  }
            return;



            //  textlistdoewn();
            //List<InvoiiceOcrModel> bpmlist = getPiaoJuAllClick();
            //List<InvoiiceOcrModel> bpmlist1 = getPiaoJuAllClick();
            //List<InvoiiceOcrModel> bpmlistA = getPiaoJuAllClick();
            //foreach (InvoiiceOcrModel iom in bpmlistA) {
            //    string invoiceNum = iom.invoiceNum;
            //    string invoiceNumSon = iom.invoiceOcrSonListSet[0].invoiceNum;
            //    if (invoiceNum=="56072669"|| invoiceNumSon== "56072669") {
            //        var ssds= "";
            //    }
            //}
            //int qrCodeNum = 0;
            //int moneyNum = 0;
            //int taxmoneyNum = 0;
            //int taxRateNum = 0;
            //int totleNum = 0;
            //int xxqrCodeNum = 0;
            //int xxmoneyNum = 0;
            //int xxtaxmoneyNum = 0;
            //int xxtaxRateNum = 0;
            //int xxtotleNum = 0;
            //int xxtotleInvoiceNum = 0;
            //int jxtotleInvoiceNum = 0;
            //int gfcomNum = 0;
            //int gftaxNum = 0;
            //int xfcomNum = 0;
            //int xftaxNum = 0;
            //int InvoiceNumAll = bpmlistA.Count;
            //if (bpmlistA.Count > 0)
            //{

            //    foreach (InvoiiceOcrModel iom in bpmlistA)
            //    {
            //        string qrCode = iom.invoiceOcrSonListSet[0].qrCode;
            //        string moneyAmount = iom.invoiceOcrSonListSet[0].moneyAmounts;
            //        string taxAmounts = iom.invoiceOcrSonListSet[0].taxAmounts;
            //        string totalMoney = iom.invoiceOcrSonListSet[0].totalMoney;
            //        string taxRate = iom.invoiceOcrSonListSet[0].taxRate;
            //        string moneyAmountsInitialValue = iom.invoiceOcrSonListSet[0].moneyAmountsInitialValue;
            //        string taxAmountsInitialValue = iom.invoiceOcrSonListSet[0].taxAmountsInitialValue;
            //        string taxRateInitialValue = iom.invoiceOcrSonListSet[0].taxRateInitialValue;
            //        string totalMoneyInitialValue = iom.invoiceOcrSonListSet[0].totalMoneyInitialValue;
            //        string isProviderOrCustomer = iom.invoiceOcrSonListSet[0].isProviderOrCustomer;
            //        string xfcompanyname = iom.invoiceOcrSonListSet[0].xfcompanyname;
            //        string xfcompanynameInitialValue = iom.invoiceOcrSonListSet[0].xfcompanynameInitialValue;
            //        string xftaxnumber = iom.invoiceOcrSonListSet[0].xftaxnumber;
            //        string xftaxnumberInitialValue = iom.invoiceOcrSonListSet[0].xftaxnumberInitialValue;
            //        string gfcompanyname = iom.invoiceOcrSonListSet[0].gfcompanyname;
            //        string gfcompanynameInitialValue = iom.invoiceOcrSonListSet[0].gfcompanynameInitialValue;
            //        string gftaxnumber = iom.invoiceOcrSonListSet[0].gftaxnumber;
            //        string gftaxnumberInitialValue = iom.invoiceOcrSonListSet[0].gftaxnumberInitialValue;
            //        if (isProviderOrCustomer == "1")
            //        {
            //            jxtotleInvoiceNum++;
            //            if (!string.IsNullOrEmpty(gfcompanyname)) {
            //                if (gfcompanyname== gfcompanynameInitialValue) {
            //                    gfcomNum++;
            //                }
            //            }
            //            if (!string.IsNullOrEmpty(gftaxnumber))
            //            {
            //                if (gftaxnumber == gftaxnumberInitialValue)
            //                {
            //                    gftaxNum++;
            //                }
            //            }
            //            if (!string.IsNullOrEmpty(qrCode))
            //            {
            //                qrCodeNum++;
            //            }
            //            if (moneyAmount == moneyAmountsInitialValue)
            //            {
            //                moneyNum++;
            //            }
            //            if (taxAmounts == taxAmountsInitialValue)
            //            {
            //                taxmoneyNum++;
            //            }
            //            if (totalMoney == totalMoneyInitialValue)
            //            {
            //                totleNum++;
            //            }
            //            if (taxRate == taxRateInitialValue)
            //            {
            //                taxRateNum++;
            //            }
            //        }
            //        else if (isProviderOrCustomer == "0")
            //        {//销项
            //            xxtotleInvoiceNum++;
            //            if (!string.IsNullOrEmpty(xfcompanyname))
            //            {
            //                if (xfcompanyname == xfcompanynameInitialValue)
            //                {
            //                    xfcomNum++;
            //                }
            //            }
            //            if (!string.IsNullOrEmpty(xftaxnumber))
            //            {
            //                if (xftaxnumber == xftaxnumberInitialValue)
            //                {
            //                    xftaxNum++;
            //                }
            //            }
            //            if (!string.IsNullOrEmpty(qrCode))
            //            {
            //                xxqrCodeNum++;
            //            }
            //            if (moneyAmount == moneyAmountsInitialValue)
            //            {
            //                xxmoneyNum++;
            //            }
            //            if (taxAmounts == taxAmountsInitialValue)
            //            {
            //                xxtaxmoneyNum++;
            //            }
            //            if (totalMoney == totalMoneyInitialValue)
            //            {
            //                xxtotleNum++;
            //            }
            //            if (taxRate == taxRateInitialValue)
            //            {
            //                xxtaxRateNum++;
            //            }
            //        }

            //    }
            //}
            //resultEd.Text = "总票据数：" + InvoiceNumAll + "二维码识别数：" + qrCodeNum;

            //List<InvoiiceOcrModel> bpmlistB = getPiaoJuAllClick();
            //int num = 0;
            //foreach (InvoiiceOcrModel bpm in bpmlist)
            //{
            //    string qrcode = bpm.invoiceOcrSonListSet[0].qrCode;
            //    if (!string.IsNullOrEmpty(qrcode))
            //    {
            //        string[] QRcodeInfo = qrcode.Split(',');
            //        if (QRcodeInfo.Count() == 9)
            //        {
            //            bpm.invoiceOcrSonListSet[0].moneyAmounts = QRcodeInfo[4];
            //        }
            //        else {
            //            bpm.invoiceOcrSonListSet[0].moneyAmounts = bpm.invoiceOcrSonListSet[0].moneyAmountsInitialValue;
            //        }
            //    }
            //    else {
            //        bpm.invoiceOcrSonListSet[0].moneyAmounts = bpm.invoiceOcrSonListSet[0].moneyAmountsInitialValue;
            //    }
            //    bpm.invoiceOcrSonListSet[0].taxAmounts = bpm.invoiceOcrSonListSet[0].taxAmountsInitialValue;
            //    bpm.invoiceOcrSonListSet[0].taxRate = bpm.invoiceOcrSonListSet[0].taxRateInitialValue;
            //    bpm.invoiceOcrSonListSet[0].totalMoney = bpm.invoiceOcrSonListSet[0].totalMoneyInitialValue;
            //    bpm.invoiceOcrDetailedDtoList = (List<invoiceOcrDetailedModel>)bpm.invoiceOcrListDetailedSet;
            //    bpm.invoiceOcrSonLists = (List<InvoiceSonModel>)bpm.invoiceOcrSonListSet;
            //}
            //foreach (InvoiiceOcrModel bpm in bpmlistA)
            //{
            //    string qrcode = bpm.invoiceOcrSonListSet[0].qrCode;
            //    if (!string.IsNullOrEmpty(qrcode))
            //    {
            //        string[] QRcodeInfo = qrcode.Split(',');
            //        if (QRcodeInfo.Count() > 5)
            //        {
            //            bpm.invoiceOcrSonListSet[0].moneyAmounts = QRcodeInfo[4];
            //        }
            //        else
            //        {
            //            bpm.invoiceOcrSonListSet[0].moneyAmounts = bpm.invoiceOcrSonListSet[0].moneyAmountsInitialValue;
            //        }
            //    }
            //    else
            //    {
            //        bpm.invoiceOcrSonListSet[0].moneyAmounts = bpm.invoiceOcrSonListSet[0].moneyAmountsInitialValue;
            //    }
            //    bpm.invoiceOcrSonListSet[0].taxAmounts = bpm.invoiceOcrSonListSet[0].taxAmountsInitialValue;
            //    bpm.invoiceOcrSonListSet[0].taxRate = bpm.invoiceOcrSonListSet[0].taxRateInitialValue;
            //    bpm.invoiceOcrSonListSet[0].totalMoney = bpm.invoiceOcrSonListSet[0].totalMoneyInitialValue;
            //    bpm.invoiceOcrDetailedDtoList = (List<invoiceOcrDetailedModel>)bpm.invoiceOcrListDetailedSet;
            //    bpm.invoiceOcrSonLists = (List<InvoiceSonModel>)bpm.invoiceOcrSonListSet;
            //}
            //try
            //{
            //    //AmountAndDetailsEtcMoney.moneyChuLi(bpmlist);
            //    InvoiceMoneysCheck.moneyChuLi(bpmlistA);
            //    // forwardingToserver(bpmlistA,ApiUrlList.DATALL);
            //}
            //catch (Exception ex)
            //{
            //    WsdLogger.yxlog("errormessage", "校验金额出错" + ex.Message);
            //}
            ////List<string> listOld = check(bpmlist1, bpmlist);
            //List<string> listNew = check(bpmlistB, bpmlistA);
            //foreach (string newlist in listNew)
            //{
            //    string messnew = newlist;
            //    int have = 0;
            //    //foreach (string oldlist in listOld)
            //    //{
            //    //    string messold = oldlist;
            //    //    if (messold == messnew)
            //    //    {
            //    //        have++;
            //    //        break;
            //    //    }
            //    //}
            //    if (have == 0)
            //    {
            //        WsdLogger.yxlog("newerrormessage", "老算法没有新算法有：" + messnew);
            //    }
            //}
            //string ss = "完事";
        }
        private void forwardingToserver(List<InvoiiceOcrModel> bpm, string apiurl)
        {
            string tpresult;
            string result = "";
            try
            {
                List<InvoiiceOcrModel> newInvoiceList = new List<InvoiiceOcrModel>();
                if (bpm[0].companyName != "上海卓顾信息科技有限公司" && bpm[0].companyTaxnum != "913101165964435306")
                {
                    result = RestOrcTool.Postlist(out tpresult, bpm, apiurl);
                }
                //ocrlog.Write("批量上传服务器返回信息：" + result);
                WsdLogger.yxlog("error", "批量上传服务器返回信息" + result + "____" + bpm.Count);
            }
            catch (Exception es)
            {
                WsdLogger.yxlog("error", "传服务错误" + es.Message);
                return;
            }
        }

        public List<string> check(List<InvoiiceOcrModel> bpmlist1, List<InvoiiceOcrModel> bpmlist)
        {
            List<string> listNewOrOld = new List<string>();
            string message = "";

            int error = 0;
            foreach (InvoiiceOcrModel bpma in bpmlist1)
            {
                if (bpma.billtype != -1)
                {
                    string moneyAmounts = bpma.invoiceOcrSonListSet[0].moneyAmounts;
                    string taxAmounts = bpma.invoiceOcrSonListSet[0].taxAmounts;
                    string taxRate = bpma.invoiceOcrSonListSet[0].taxRate;
                    string totalMoney = bpma.invoiceOcrSonListSet[0].totalMoney;


                    moneyAmounts = InvoiceMoneysCheck.changNumberDelZero(moneyAmounts);
                    taxAmounts = InvoiceMoneysCheck.changNumberDelZero(taxAmounts);
                    totalMoney = InvoiceMoneysCheck.changNumberDelZero(totalMoney);
                    decimal moneyAmount;
                    decimal taxAmount;
                    decimal totleAmount;
                    decimal.TryParse(moneyAmounts, out moneyAmount);
                    decimal.TryParse(taxAmounts, out taxAmount);
                    decimal.TryParse(totalMoney, out totleAmount);
                    moneyAmounts = moneyAmount.ToString("#0.00");
                    taxAmounts = taxAmount.ToString("#0.00");
                    totalMoney = totleAmount.ToString("#0.00");
                    string errorMessageNum = "";
                    int id = bpma.id;
                    error++;
                    foreach (InvoiiceOcrModel bpmb in bpmlist)
                    {
                        int numerror = 0;
                        string moneyAmountsb = bpmb.invoiceOcrSonLists[0].moneyAmounts;
                        string taxAmountsb = bpmb.invoiceOcrSonLists[0].taxAmounts;
                        string taxRateb = bpmb.invoiceOcrSonLists[0].taxRate;
                        string totalMoneyb = bpmb.invoiceOcrSonLists[0].totalMoney;
                        string isProviderOrCustomer = bpmb.invoiceOcrSonListSet[0].isProviderOrCustomer;
                        string biaozhi = "";
                        if (isProviderOrCustomer == "0")
                        {
                            biaozhi = "销项";
                        }
                        else if (isProviderOrCustomer == "1")
                        {
                            biaozhi = "进项";
                        }

                        if (id == bpmb.id)
                        {
                            if (moneyAmounts != moneyAmountsb)
                            {
                                WsdLogger.yxlog("errormessage", "第" + error + "条金额不正确进销项标志为" + biaozhi + " id号为" + bpmb.id);
                                message += "第" + error + "条金额不正确 id号为" + bpmb.id + "\r\n";
                                string messages = "第" + error + "条金额不正确 id号为" + bpmb.id;
                                numerror++;
                                errorMessageNum += " 正确金额：" + moneyAmounts + "错误金额：" + moneyAmountsb + "金额错误，";
                                listNewOrOld.Add(messages);
                            }
                            if (taxRate != taxRateb)
                            {
                                WsdLogger.yxlog("errormessage", "第" + error + "条税率不正确 id号为" + bpmb.id);
                                message += "第" + error + "条税率不正确 id号为" + bpmb.id + "\r\n";
                                string messages = "第" + error + "条税率不正确 id号为" + bpmb.id;
                                numerror++;
                                errorMessageNum += " 正确税率：" + taxRate + "错误税率：" + taxRateb + "税率错误，";
                                listNewOrOld.Add(messages);
                            }
                            if (taxAmounts != taxAmountsb)
                            {
                                WsdLogger.yxlog("errormessage", "第" + error + "条税额不正确 id号为" + bpmb.id);
                                message += "第" + error + "条税额不正确 id号为" + bpmb.id + "\r\n";
                                string messages = "第" + error + "条税额不正确 id号为" + bpmb.id;
                                numerror++;
                                errorMessageNum += " 正确税额：" + taxAmounts + "错误税额：" + taxAmountsb + "税额错误，";
                                listNewOrOld.Add(messages);
                            }
                            if (totalMoney != totalMoneyb)
                            {
                                WsdLogger.yxlog("errormessage", "第" + error + "条价税合计不正确 id号为" + bpmb.id);
                                message += "第" + error + "条价税合计不正确 id号为" + bpmb.id + "\r\n";
                                string messages = "第" + error + "条价税合计不正确 id号为" + bpmb.id;
                                numerror++;
                                errorMessageNum += " 正确合计：" + totalMoney + "错误合计：" + totalMoneyb + "合计错误，";
                                listNewOrOld.Add(messages);
                            }
                            errorMessageNum += "本条共错：" + numerror + "条进销项标志为" + biaozhi + " id为" + bpmb.id + "\r\n";
                            WsdLogger.yxlog("errormessageNumber", errorMessageNum);
                            break;
                        }
                    }
                }
            }
            //resultEd.Text = errorMessageNum;
            //resultEd.Text = message;
            return listNewOrOld;
        }
        private List<InvoiiceOcrModel> getPiaoJuAllClick()
        {
            List<InvoiiceOcrModel> bpmlist = new List<InvoiiceOcrModel>();
            InvoiiceOcrModel bm = new InvoiiceOcrModel();
            InvoiceOcrTaxtjtable iotjb = new InvoiceOcrTaxtjtable();
            string tpresult = "";
            string apiurl2 = ApiUrlList.GETDATAALL;
            string apiurl2Tongji = ApiUrlList.SELECTTJTABLE;
            string result = "";
            bm.declaredate = "202002";
            //   bm.currentTime = "2019-11-28";
            //bm.addTime = "2019-11-28";
            //  iotjb.zhibiaoDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            result = RestDataTool.Post2(out tpresult, bm, apiurl2, out bpmlist);
            return bpmlist;
        }
        private List<InvoiiceOcrModel> getPiaoJuAllClick1()
        {
            List<InvoiiceOcrModel> bpmlist1 = new List<InvoiiceOcrModel>();
            InvoiiceOcrModel bm = new InvoiiceOcrModel();
            InvoiceOcrTaxtjtable iotjb = new InvoiceOcrTaxtjtable();
            string tpresult = "";
            string apiurl2 = ApiUrlList.GETDATAALL;
            string apiurl2Tongji = ApiUrlList.SELECTTJTABLE;
            string result = "";
            bm.declaredate = "201908";
            iotjb.zhibiaoDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            result = RestDataTool.Post2(out tpresult, bm, apiurl2, out bpmlist1);
            return bpmlist1;
        }
        public void getTaxNo(string companyName)
        {

        }
        private void textlistdoewn()
        {
            StringBuilder sb = new StringBuilder();
            List<BatchInfo> compList = HongFengCompanyOrVendorsTool.VendorscompanyAll;
            string fileName = "VendorscompListData";
            foreach (BatchInfo bi in compList)
            {
                sb.AppendFormat("{0}-{1}" + "\r\n", bi.companyName, bi.companyTaxnum);//这里几列，写几列
            }
            string texurl = AppDomain.CurrentDomain.BaseDirectory + "VendorscompListData.txt";
            File.WriteAllText(texurl, sb.ToString());//写入文件
            foreach (string str in File.ReadAllLines(texurl, Encoding.Default))
            {
                Console.WriteLine(str); // str就是每一行数据
            }
        }

        //将List转换为TXT文件

        public void WriteListToTextFile(List<BatchInfo> list, string txtFile)

        {
            //创建一个文件流，用以写入或者创建一个StreamWriter
            FileStream fs = new FileStream(txtFile, FileMode.OpenOrCreate, FileAccess.Write);
            StreamWriter sw = new StreamWriter(fs);
            sw.Flush();
            // 使用StreamWriter来往文件中写入内容
            sw.BaseStream.Seek(0, SeekOrigin.Begin);
            for (int i = 0; i < list.Count; i++)
            {
                sw.WriteLine(list[i]);
            }

            //关闭此文件

            sw.Flush();

            sw.Close();

            fs.Close();

        }
    }
}
